const express = require('express');
const router = express.Router();
const utils = require("../utils/index.js");
const {primary} = require("../utils/roleString");
const pools = require("../utils/pools.js");

// 获取登录日志列表
router.post('/list', async (req, res) => {
    try {
        const { userName } = req.body;
        let sql = 'SELECT * FROM login_log WHERE 1=1';
        const params = [];
        if (userName) {
            sql += ' AND user_name LIKE ' + '"%'+userName+'%"';
            // params.push(`%${name}%`);
        }
        await pools({sql, val:params,res,req,run:false});
    } catch (error) {
        console.error('获取登录日志列表失败:', error);
        res.json(utils.error('获取登录日志列表失败'));
    }
});

//删除日志
router.post('/delete', async (req, res) => {
    try {
        const { id } = req.body;
        const sql = 'DELETE FROM login_log WHERE id = ?';
        await pools({sql, val:[id],run:false,res,req});
    } catch (error) {
        console.error('删除日志失败:', error);
        res.json(utils.error('删除日志失败'));
    }
});


module.exports = router;